﻿Public Class xtf_LogIn
    Public obj_usuarioLOG As cls_usuario_ = Nothing
    Dim Intentos As Integer = 0
    Private Sub txt_Usuario_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt_usuario.KeyPress
        If e.KeyChar = Chr(13) Then
            txt_Contraseña.Focus()
        End If
    End Sub

    Private Sub btn_Aceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Aceptar.Click
        Dim usuarioLogIn As New cls_usuario_
        If usuarioLogIn.BuscarXusuarioXcontraseña(txt_usuario.Text, txt_Contraseña.Text) Then
            obj_usuarioLOG = New cls_usuario_
            obj_usuarioLOG = usuarioLogIn
            Me.DialogResult = Windows.Forms.DialogResult.OK
        Else
            Intentos += 1
            If Intentos = 3 Then
                Me.DialogResult = Windows.Forms.DialogResult.Cancel
            End If
            obj_usuarioLOG = Nothing
            Me.TopMost = False
            ErrManagerShow("000006", Me)
            Me.TopMost = True
            txt_Contraseña.Text = ""
            txt_usuario.SelectAll()
            txt_usuario.Focus()
        End If
    End Sub

    Private Sub txt_Contraseña_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt_Contraseña.KeyPress
        If e.KeyChar = Chr(13) Then
            'btn_Aceptar.Focus()
            btn_Aceptar_Click(Nothing, Nothing)
        End If
    End Sub

    Private Sub btn_Cancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Cancelar.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub xtf_LogIn_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated

    End Sub


    Private Sub frm_LogIn_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim UsuarioComprobar As New cls_usuario_
        If UsuarioComprobar.BuscarXusuario(Environment.UserName) Then
            txt_usuario.Text = Environment.UserName
        End If
        txt_usuario.Focus()
    End Sub

    Public Sub New()

        ' Llamada necesaria para el Diseñador de Windows Forms.
        InitializeComponent()
        Me.Text = "Ingreso al sistema"
        Me.Icon = ico_AppIcono
        If autologinroot Then
            txt_usuario.Text = "root"
            txt_Contraseña.Text = "Gundys-2000"
        End If
        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().

    End Sub


    Private Sub xtf_LogIn_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        If txt_usuario.Text <> "" Then
            txt_Contraseña.Focus()
        End If
    End Sub
End Class